var app = new Vue({
	el:"#sharing",
	data () {
	  return {
      sharelist: null, // 分享列表数据
      currentPage: 1,
      totalPage: "",
      loading: false
	  }
  },
  created () {
    this.getShareData()
  },
	methods: {
    goback () {
      let url = document.referrer
      if (url.indexOf('msg') > -1) {
        window.location.href = '../../msg/msg.html'  
      } else {
        window.location.href = '../../myTask/myTask.html'
      }
    },
    // 滚动加载更多商品
    loadMore(){
      setTimeout(() => {
        this.currentPage ++
        if(this.currentPage > this.totalPage){
          this.loading = true
            return false
        }
        this.getShareData()
      }, 2000);
    }, 
    // 获取分享商品列表数据
	  getShareData () {
      Axios.post('/order/custom/selfOrderMessage.do',{
        currentPage: this.currentPage
      }).then(res => {
        if (res.respCode === "S") {
          let list = res.data.data
          list.forEach(share => {
            share.createTime = new Date(share.createTime).Format('yy/MM/dd')
          });
          if (this.currentPage == 1) {
            this.sharelist = list
          } else {
            this.sharelist = this.sharelist.concat(list)
          }
          this.totalPage = res.data.totalPage
          if (this.currentPage < this.totalPage) {
            this.loading = false
          }
        } else {
          this.sharelist = []
        }
			}).catch(err => {
        console.error(err)
      })
    },
    // 无价格按钮
    btnNoPrice (index) {
      Axios.post('/order/custom/handleCustomOrder.do',{
        messageId: this.sharelist[index].messageId,
        selfOrderId: this.sharelist[index].selfOrderId,
        priceNum: "无"
      }).then(res => {
        if (res.respCode === "S") {
          this.sharelist[index].status = "SUCCESS"
        }
			}).catch(err => {
        console.error(err)
      })
    },
    // 有价格按钮
    btnHavePrice (index) {
      Axios.post('/order/custom/handleCustomOrder.do',{
        messageId: this.sharelist[index].messageId,
        selfOrderId: this.sharelist[index].selfOrderId,
        priceNum: "有"
      }).then(res => {
        if (res.respCode === "S") {
          this.sharelist[index].status = "SUCCESS"
        }
			}).catch(err => {
        console.error(err)
      })
    },
    // 分享跳转按钮
    btnShareJump (item) {
      window.location.href = "../priceCcorrection/shareAndCorrection.html?brandName=" + item.brandName + '&goodsName=' + item.goodsName + '&attrValue=' + item.attrValue
    }
	}
})